#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int a[N];
int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    cin >> t;
    while(t--)
    {
        memset(a, 0, sizeof a);
        int n, ans = 0;
        cin >> n;
        for(int i = 1; i <= n; i++) cin >> a[i];
       // cout << endl;
        for(int i = 0; i < (1 << n); i++)
        {
            int now[N], c[N];
            int k = i;
            for(int j = 1; j <= n; j++)
            {
                if((k & 1) == 1) now[j] = 1;
                else now[j] = 0;
                k >>= 1;
            }
            int re = 0, bl = 0, ans2 = 0;
            //for(int j = 1; j <= n; j++) cout << now[i] << " ";
            //cout << endl;
            for(int j = 1; j <= n; j++)
            {
                if(now[j] == 1)
                {
                    if(a[j] == a[re]) c[j] = a[j];
                    else c[j] = 0;
                    re = j;
                }
                else
                {
                    if(a[j] == a[bl]) c[j] = a[j];
                    else c[j] = 0;
                    bl = j;
                }
                ans2 += c[j];
            }
            ans = max(ans, ans2);
        }
        cout << ans << endl;
    }
    return 0;
}
